﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;

namespace WebJobAsTimerService
{
    // To learn more about Microsoft Azure WebJobs SDK, please see http://go.microsoft.com/fwlink/?LinkID=320976
    class Program
    {
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        public static void Main()
        {
            try
            {
                Console.WriteLine("Begin");                
                var f = new Functions();                
                f.ProcessEmailList();
                Console.WriteLine("End");
            }
            catch (AggregateException ae)
            {
                //This exception will be thrown by any Async methods
                Console.WriteLine("Exceptions:");
                foreach (var e in ae.InnerExceptions)
                    Console.WriteLine(e.Message);

                throw ae.InnerExceptions[0];

            }catch(Exception e)
            {
                //This exception will be thrown by any Non async methods
                Console.WriteLine("Exception: {0}, {1}", e.Message, e.StackTrace);
                throw e;
            }
        }
    }
}
